# Copyright (c) 2021 Presto Labs Pte. Ltd.
# Author: leon, gekim

import requests
from coin2.exchange.product_info import ProductInfoDefault
from coin2.exchange.symbology import SymbologyInfo


def generate():
  mea = 'Spot.Bitbank.v1'
  me = 'Spot.Bitbank'
  default = ProductInfoDefault()
  symbol_info = SymbologyInfo()
  pairs = requests.get('https://api.bitbank.cc/v1/spot/pairs').json()['data']['pairs']

  pis = []
  for info in pairs:
    native_symbol = info['name']
    native_base = info['base_asset']
    native_quote = info['quote_asset']
    base = symbol_info.native_to_norm_currency(mea, native_base)
    quote = symbol_info.native_to_norm_currency(mea, native_quote)
    symbol = "%s-%s" % (base, quote)

    pi = dict(
        symbol=symbol,
        base=base,
        quote=quote,
        native_symbol=native_symbol,
        native_base=native_base,
        native_quote=native_quote,
        price_ticksize=10 ** (-info['price_digits']),
        qty_ticksize=10 ** (-info['amount_digits']),
    )

    pi = {**pi, **default.product_info(me, symbol)}
    pis.append(pi)

  pis = sorted(pis, key=lambda x: x['symbol'])
  return pis


if __name__ == "__main__":
  import json
  print(json.dumps(generate(), indent=2))
